/**
 * Project Name:kany-project-blog-web
 * File Name:IndexResource.java
 * Package Name:me.kany.project.blog.resource
 * Date:2016年9月20日下午11:38:21
 * Copyright (c) 2016, Jason.Wang All Rights Reserved.
 */
package me.kany.project.blog.resource;


import javax.annotation.security.RolesAllowed;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;


/**
 * ClassName:IndexResource<br/>
 * Function: 主方法<br/>
 * Date:2016年9月14日上午11:22:04<br/>
 * 
 * @author Jason.Wang
 * @version 1.0
 * @since JDK1.7
 * @see
 */
@Path("/")
@Component
public class IndexResource {
	
	@GET
	@RolesAllowed({"user", "admin"})
	@Path("json/{name}")
	@Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
	public JSONObject json(@PathParam("name") String name){
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("name", name);
		return jsonObject;
	}
	
	@GET
	@RolesAllowed({"user", "admin"})
	@Path("request")
	@Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
	public JSONObject json(@Context HttpServletRequest request){
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("name", request.getParameter("name"));
		return jsonObject;
	}
	
	@POST
	@RolesAllowed({"user", "admin"})
	@Path("form")
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    @Produces(MediaType.APPLICATION_JSON)
	public JSONObject form(@FormParam("name") String name){
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("name", name);
		return jsonObject;
	}
}

